﻿using AbpProjectTemplate.Identity;
using AbpProjectTemplate.MultiTenancy;
using Jy.Abp.GeneralTree;
using Jy.Abp.SettingManagement;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using System;
using Volo.Abp.Auditing;
using Volo.Abp.AuditLogging;
using Volo.Abp.AutoMapper;
using Volo.Abp.BackgroundJobs;
using Volo.Abp.Domain.Entities.Caching;
using Volo.Abp.Emailing;
using Volo.Abp.FeatureManagement;
using Volo.Abp.Identity;
using Volo.Abp.Localization;
using Volo.Abp.Modularity;
using Volo.Abp.MultiTenancy;
using Volo.Abp.OpenIddict;
using Volo.Abp.PermissionManagement.Identity;
using Volo.Abp.PermissionManagement.OpenIddict;
using Volo.Abp.TenantManagement;
using Volo.Abp.Timing;

namespace AbpProjectTemplate;

[DependsOn(
    typeof(AppDomainSharedModule),
    typeof(AbpAuditLoggingDomainModule),
    typeof(AbpBackgroundJobsDomainModule),
    typeof(AbpFeatureManagementDomainModule),
    typeof(AbpIdentityDomainModule),
    typeof(AbpOpenIddictDomainModule),
    typeof(AbpPermissionManagementDomainOpenIddictModule),
    typeof(AbpPermissionManagementDomainIdentityModule),
    typeof(JyAbpSettingManagementDomainModule),
    typeof(JyAbpGeneralTreeDomainModule),
    typeof(AbpTenantManagementDomainModule),
    typeof(AbpEmailingModule)
)]
public class AppDomainModule : AbpModule
{
    public override void ConfigureServices(ServiceConfigurationContext context)
    {
        Configure<AbpLocalizationOptions>(options =>
        {
            options.Languages.Add(new LanguageInfo("en", "en", "English"));
            options.Languages.Add(new LanguageInfo("zh-Hans", "zh-Hans", "简体中文"));
        });

        this.Configure<AbpAuditingOptions>(options =>
        {
            options.IsEnabledForAnonymousUsers = false;
        });
        this.Configure<AbpBackgroundJobOptions>(options =>
        {
            //#if DEBUG
            //            options.IsJobExecutionEnabled = false;
            //#endif
        });
        Configure<AbpMultiTenancyOptions>(options =>
        {
            options.IsEnabled = MultiTenancyConsts.IsEnabled;
        });

#if DEBUG
        context.Services.Replace(ServiceDescriptor.Singleton<IEmailSender, NullEmailSender>());
#endif
        Configure<AbpAutoMapperOptions>(options =>
        {
            options.AddMaps<AppDomainModule>();
        });

        //Configure<AbpClockOptions>(options =>
        //{
        //    options.Kind = DateTimeKind.Utc;
        //});


        context.Services.AddEntityCache<IdentityUser, IdentityUserCacheItem, Guid>();
    }
}
